{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import logging"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "logger = logging.getLogger(\"logger_name\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Logging at warning\n",
      "Logging at error\n",
      "Logging at fatal\n"
     ]
    }
   ],
   "source": [
    "logger.debug(\"Logging at debug\")\n",
    "logger.info(\"Logging at info\")\n",
    "logger.warning(\"Logging at warning\")\n",
    "logger.error(\"Logging at error\")\n",
    "logger.fatal(\"Logging at fatal\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "0 errors reported in moon\n",
      "1 errors reported in moon\n",
      "2 errors reported in moon\n"
     ]
    }
   ],
   "source": [
    "system = \"moon\"\n",
    "for number in range(3):\n",
    "    logger.warning(\"%d errors reported in %s\", number, system)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "ERROR:root:Something bad happened: 'missing_key'\n"
     ]
    }
   ],
   "source": [
    "d = dict()\n",
    "try:\n",
    "    d[\"missing_key\"] += 1\n",
    "except Exception as e:\n",
    "    logging.error(\"Something bad happened: %s\", e)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
